package com.study.demo.repository;

import com.study.demo.dto.Info;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Repository
public interface InfoRepository extends JpaRepository<Info, Serializable> {

    @Query("from Info i where i.flag=?1 and i.id>?2 order by i.id desc")
    List<Info> searchByFlagAndPos(Integer flag, Integer pos);

    @Transactional
    @Modifying
    @Query("update Info i set i.flag=0 where i.id=?1")
    void updateFlagById(Integer id);
}
